﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using Mangosoft.DiceCopy.DistributedServices.MainBoundedContext.InstanceProviders;
using Mangosoft.DiceCopy.DistributedServices.Seedwork.ErrorHandlers;
using Mangosoft.DiceCopy.Application.MainBoundedContext.DTO;
using Mangosoft.DiceCopy.Application.MainBoundedContext.JobHuntingModule.Services;

namespace Mangosoft.DiceCopy.DistributedServices.MainBoundedContext {
    [ApplicationErrorHandlerAttribute()] // manage all unhandled exceptions
    [UnityInstanceProviderServiceBehavior()] //create instance and inject dependencies using unity container
    [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]
    public class JobHuntingModuleService : IJobHuntingModuleService {

        #region Members
        private readonly IJobseekerAppService _jobseekerAppService;
        private readonly IJobHuntingAppService _jobHuntingAppService;
        private readonly IResumeAppService _resumeAppService;
        #endregion

        public JobHuntingModuleService(IJobseekerAppService jobseekerAppService,
            IJobHuntingAppService jobHuntingAppService) {

            if (jobseekerAppService == null)
                throw new ArgumentNullException("Jobseeker");

            if (jobHuntingAppService == null)
                throw new ArgumentNullException("JobHunting");

            _jobseekerAppService = jobseekerAppService;
            _jobHuntingAppService = jobHuntingAppService;
        }



        public List<JobseekerDTO> FindJobseekers() {
            return _jobseekerAppService.FindJobseekers();
        }

        public JobseekerDTO FindJobseeker(Guid id) {
            return _jobseekerAppService.FindJobseeker(id);
        }

        public List<NewsDTO> FindNews() {
            return _jobHuntingAppService.FindNews();
        }

        public List<NewsDTO> FindNewsByChannel(int channel) {
            return _jobHuntingAppService.FindNewsByChannel(channel);
        }

        public List<AdvertisingDTO> FindAdvertisingsByBlock(int blockcode) {
            return _jobHuntingAppService.FindAdvertisingByBlock(blockcode);
        }

        public ResumeDTO AddNewResume(ResumeDTO resume) {
            return _jobHuntingAppService.AddNewResume(resume);
        }

        #region CoverLetter's AppService
        public CoverLetterDTO AddNewCoverLetter(CoverLetterDTO coverLetter) {
            return _resumeAppService.AddNewCoverLetter(coverLetter);
        }

        public void UpdateCoverLetter(CoverLetterDTO coverLetter) {
            _resumeAppService.UpdateCoverLetter(coverLetter);
        }

        public void RemoveCoverLetter(Guid coverLetterId) {
            _resumeAppService.RemoveCoverLetter(coverLetterId);
        }

        public CoverLetterDTO FindCoverLetter(Guid coverLetterId) {
            return _resumeAppService.FindCoverLetter(coverLetterId);
        }

        public List<CoverLetterDTO> FindCoverLetters(string text) {
            return _resumeAppService.FindCoverLetters(text);
        }
        #endregion
    }
}
